package com.tbvtc.agriculturalcreditchainserver2025.service.impl;



import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.tbvtc.agriculturalcreditchainserver2025.service.SmsService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Log
public class SmsServiceImpl implements SmsService {

    @Autowired
     private Client client;

    @Override
    public void sendCode(String phone, String code) {
        SendSmsRequest smsRequest = new SendSmsRequest(); // 创建请求对象
        smsRequest.setPhoneNumbers(phone); // 设置手机号
        smsRequest.setSignName("天津市北辰一些程序员公司"); // 设置签名
        smsRequest.setTemplateCode("SMS_323815067"); // 设置模板代码
        smsRequest.setTemplateParam("{\"code\":\"" + code + "\"}"); // 设置模板参数
        try {
            SendSmsResponse sendSmsResponse = client.sendSms(smsRequest);
            System.out.println(sendSmsResponse.getStatusCode());
            System.out.println(sendSmsResponse.getBody().getMessage());
            System.out.println(sendSmsResponse.getBody().getCode());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void sendPestCode(String phone, String farmName) {
        SendSmsRequest smsRequest = new SendSmsRequest(); // 创建请求对象
        smsRequest.setPhoneNumbers(phone); // 设置手机号
        smsRequest.setSignName("天津市北辰一些程序员公司"); // 设置签名
        smsRequest.setTemplateCode("SMS_492605168"); // 设置模板代码
        smsRequest.setTemplateParam("{\"farmName\":\"第五块\"}"); // 设置模板参数
//        smsRequest.setTemplateParam("{\"name\":\"张三\",\"farmName\":\"22号\"}");  // 设置模板参数
        try {
            SendSmsResponse sendSmsResponse = client.sendSms(smsRequest);
            System.out.println(sendSmsResponse.getStatusCode());
            System.out.println(sendSmsResponse.getBody().getMessage());
            System.out.println(sendSmsResponse.getBody().getCode());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



}
